package com.bobo.Base64;

import java.io.IOException;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * Java的三种Base64的编码与解码
 * @author win7
 *
 */
public class Base64Test {

	public static String code="www.bobo.com";
	/**
	 * JDK自己的base64  BASE64Encoder
	 * @throws IOException
	 */
	public void JdkBase64() throws IOException{
		BASE64Encoder base64Encode=new BASE64Encoder();
		String basecode= base64Encode.encode(code.getBytes());
		System.out.println("BASE64Encoder编码："+basecode);
		BASE64Decoder base64Decoder=new BASE64Decoder();
		byte[] bytedecoder= base64Decoder.decodeBuffer(basecode);
		System.out.println("BASE64Encoder解码："+new String(bytedecoder));
		
	}
	/**
	 * 1.com.sun.org.apache.xerces.internal.impl.dv.util.Base64
	 * 2.com.sun.xml.internal.messaging.saaj.util.Base64
	 */
	public void commons_codec(){
		Base64 base=new Base64();
		com.sun.xml.internal.messaging.saaj.util.Base64 base2=new com.sun.xml.internal.messaging.saaj.util.Base64();
		String sss=  base.encode(code.getBytes());
		byte[] sss2= base2.encode(code.getBytes());
		System.out.println("com.sun.org.apache.xerces.internal.impl.dv.util.Base64 编码："+sss);
		System.out.println("com.sun.org.apache.xerces.internal.impl.dv.util.Base64 解码："+new String(base.decode(sss)));
		System.out.println("com.sun.xml.internal.messaging.saaj.util.Base64 编码："+new String(sss2)); 
		System.out.println("com.sun.xml.internal.messaging.saaj.util.Base64 解码："+new String(base2.decode(sss2)));
	}
	
	public static void main(String[] args) {
		Base64Test base64Test=new Base64Test();
		try {
			base64Test.JdkBase64();
			base64Test.commons_codec();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
